#pragma once

#include <QObject>
#include <stdio.h>
#include <string.h>
#include <vector>
#include<iostream>
#include<thread>
#include "AlazarApi.h"
#include "AlazarCmd.h"
#include "AlazarDSP.h"
#include "AlazarError.h"
#include "ATS_CUDA.h"
#include "ATS_CUDA_OCT.h"
#include "ATS_GPU.h"
#include "ATS_GPU_OCT.h"
#include "pciout.h"
#include <list>
#include <conio.h>

//opencv

#include "opencv2/opencv.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc/types_c.h"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/highgui/highgui_c.h"
#include "../processing.h"
#include "qstring.h"


#define ERROR_CHECK(x)                                                         \
    do {                                                                       \
        RETURN_CODE retCode = (x);                                             \
        if (retCode != ApiSuccess) {                                           \
            emit error(QString("Error: ") + #x + "failed with :" + AlazarErrorToText(retCode));                                \
            success = FALSE;                                                   \
            goto exit;                                                         \
        }                                                                      \
    } while (0)

#define STREAM_NUM 12

class AcquirePro : public QObject
{
	Q_OBJECT

public:
	AcquirePro(Processing *proc);
	void start_show();
	void stop_show();
private:
	bool isAcquire = false;
	bool isshow = true;

	U32 systemId;
	U32 boardId;

	U32 deviceCount;
	U32 deviceIndex;
	HANDLE m_boardHandle;
	int success;

	Processing *mpproc;
	bool configureBoard();
	std::list<unsigned short*> listSaveBuffer;

	static unsigned __stdcall CreateSignal(void* param);
	static unsigned __stdcall SaveData(void* param);
	bool acquireData();

	void saveData();
	void createSignal();

public slots :
	void slot_show(bool isstart);

signals :
	void info(QString info);
	void error(QString error);
	void image_ready(const QImage &img);
	void sig_stop_collect();
	void sig_start_collect();
	void sig_start_show();
};